package com.example.joewang.repluginmotion.plugin;

import java.lang.reflect.Field;

public class ReflectionUtils {


    public static Object getFieldObject(Class clz, String name, Object instance) {
        try {
            Field fieldName = clz.getDeclaredField(name);
            fieldName.setAccessible(true);
            return fieldName.get(instance);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Field getField(Class clz, String name) {
        try {
            Field fieldName = clz.getDeclaredField(name);
            fieldName.setAccessible(true);
            return fieldName;
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void setField(Class clz, String name, Object instance, Object value) {
        try {
            Field fieldName = clz.getDeclaredField(name);
            fieldName.setAccessible(true);
            fieldName.set(instance, value);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}
